<template>
  <div style="padding-bottom: 20px;padding-right: 20px;">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px" :label-position="'left'">
      <el-form-item label="移库编号" prop="move_code">
        <el-input v-model="queryParams.move_code" placeholder="移库编号" clearable size="mini" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      border
      fit
      style="width: 100%">
      <el-table-column label="移库编号" prop="move_code" show-overflow-tooltip/>
      <el-table-column label="移库总量" prop="number" />
      <el-table-column label="已移库量" prop="move_number" />
      <el-table-column label="移库状态" prop="move_status">
        <template v-slot="scope">
          <span v-if="scope.row.move_status == 0">未移库</span>
          <span v-if="scope.row.move_status == 1">部分移库</span>
          <span v-if="scope.row.move_status == 2">全部移库</span>
        </template>
      </el-table-column>
      <el-table-column label="添加人" prop="username" />
      <el-table-column label="添加时间" prop="created_at" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template v-slot="scope">
          <el-button
            v-if="scope.row.move_status == 2 && scope.row.edi_return == 0"
            size="mini"
            type="success"
            @click="handleReturn(scope.row)">回传</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { ediDataReturn } from '@/api/edi'
import { getMoveMain, getStock, moveCreate, att, getSon, MoveMainCreate, split } from '@/api/stock'
export default {
  name: "Move",
  data() {
    return {
      queryParams: {
        page: 1,
        limit: 10
      },
      list: [],
      loading: true,
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询清单列表 */
    getList() {
      this.loading = true
      getMoveMain(this.queryParams).then(response => {
        this.list = response.data
        this.total = response.count
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        limit: 20
      }
      this.handleQuery()
    },
    handleReturn(row){
      this.$confirm('正在进行edi操作, 请确认?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = false
        ediDataReturn({type:'移库',record_id:row.id}).then(response => {
          this.loading = false
          if (response.code == 10000) {
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.getList()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消操作'
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
